package org.particlethink.auth;

import org.particlethink.model.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.Collections;

//@Component("UserDetailsService")
//@ConditionalOnExpression("#{'dev'.equals('${spring.profiles.active}')}")
public class DevUserDetailService implements UserDetailsService {

    private static final String projectUserToken = "projectUserToken";
    private static final String projectUserToken2 = "projectUserToken2";
    private static final String projectUserToken3 = "projectUserToken3";
    private static final String projectUserToken4 = "projectUserToken4";
    private static final String projectUserToken5 = "projectUserToken5";

    private static final String companyUserToken = "companyUserToken";
    private static final String SupplierUserToken = "supplierUserToken";
    private static final String SupplierUserToken2 = "supplierUserToken2";
    private static final String SupplierUserToken3 = "supplierUserToken3";
    private static final String SupplierUserToken4 = "supplierUserToken4";
    private static final String SupplierUserToken5 = "supplierUserToken5";


    @Override
    public UserDetails loadUserByUsername(String token) throws UsernameNotFoundException {
        User user = new User();
        DefaultUser defaultUser = new DefaultUser();
        defaultUser.setUser(user);
        user.setToken(token);
        switch (token) {
            case projectUserToken:
                user.setUsername("项目用户1");
                user.setUserId(1);
                user.setPhone("1234567890");
                user.setProjectIds(Collections.singletonList(1));
                return defaultUser;
            case companyUserToken:
                user.setUsername("公司用户");
                user.setUserId(2);
                user.setPhone("1234567890");
                user.setCompanyId(1);
                return defaultUser;
            case SupplierUserToken:
                user.setUsername("供应商用户");
                user.setUserId(3);
                user.setPhone("1234567890");
                user.setSupplierIds(Collections.singletonList(1));
                return defaultUser;
            case projectUserToken2:
                user.setUsername("项目用户2");
                user.setUserId(4);
                user.setPhone("1234567890");
                user.setProjectIds(Collections.singletonList(2));
                return defaultUser;
            case projectUserToken3:
                user.setUsername("项目用户3");
                user.setUserId(5);
                user.setPhone("1234567890");
                user.setProjectIds(Collections.singletonList(3));
                return defaultUser;


            case projectUserToken4:
                user.setUsername("项目用户4");
                user.setUserId(10);
                user.setPhone("1234567890");
                user.setProjectIds(Collections.singletonList(4));
                return defaultUser;
            case projectUserToken5:
                user.setUsername("项目用户5");
                user.setUserId(11);
                user.setPhone("1234567890");
                user.setProjectIds(Collections.singletonList(5));
                return defaultUser;
            case SupplierUserToken2:
                user.setUsername("供应商用户2");
                user.setUserId(6);
                user.setPhone("1234567890");
                user.setSupplierIds(Collections.singletonList(2));
                return defaultUser;
            case SupplierUserToken3:
                user.setUsername("供应商用户3");
                user.setUserId(7);
                user.setPhone("1234567890");
                user.setSupplierIds(Collections.singletonList(3));
                return defaultUser;
            case SupplierUserToken4:
                user.setUsername("供应商用户4");
                user.setUserId(8);
                user.setPhone("1234567890");
                user.setSupplierIds(Collections.singletonList(4));
                return defaultUser;
            case SupplierUserToken5:
                user.setUsername("供应商用户5");
                user.setUserId(9);
                user.setPhone("1234567890");
                user.setSupplierIds(Collections.singletonList(5));
                return defaultUser;
        }
        return null;
    }
}
